package com.xin.springbootjurisdiction.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.util.List;

/**
 * Created by zz on 2017/7/30.
 */
public class JsonUtil {

    public static String toJson(Object object){
        GsonBuilder gsonBuilder=new GsonBuilder();
        gsonBuilder.setPrettyPrinting();
        Gson gson=gsonBuilder.create();
        return gson.toJson(object);
    }

    //json转List
    public static <T> List<T> getList(String json,Class<T> tClass ){
            Gson gson=new Gson();
        List<T> retList = gson.fromJson(json,
                new TypeToken<List<T>>() {
                }.getType());
        return retList;
    }
}
